package com.city.itis.action;

import java.util.Map;

import javax.annotation.Resource;

import com.city.itis.domain.Member;
import com.city.itis.domain.User;
import com.city.itis.service.MemberService;
import com.city.itis.service.UserService;
import com.city.itis.util.Constants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 登陆系统管理Action
 * @author WY
 *
 */
public class LoginAction extends ActionSupport 
{
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String password;
	private String loginType;
	private UserService userService;
	private MemberService memberService; 
	private String url;
	
	public String execute()throws Exception
	{
		Map<String,Object>map=null;
		
		if(Constants.MEMBER.equals(loginType))
		{
			int flag=memberService.login(id, password);
			
			if(flag>0)
			{
				Member member=memberService.getMemberById(id);
				map=ActionContext.getContext().getSession();
				map.put("login_user", member);
				url="/member/member_maint.jsp";
				return SUCCESS;
			}else
			{
				return LOGIN;
			}
		}else
		{
			int flag=userService.login(id, password);
			
			if(flag>0)
			{
				User user=userService.getUserById(id);
				map=ActionContext.getContext().getSession();
				map.put("login_user", user);
				
				url="/admin_index.action";
				return SUCCESS;
			}else
			{
				return LOGIN;
			}
			
		}
	}
	
	
	
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getLoginType() {
		return loginType;
	}
	public void setLoginType(String loginType) {
		this.loginType = loginType;
	}
	
	public UserService getUserService() {
		return userService;
	}



	@Resource
	public void setUserService(UserService userService) {
		this.userService = userService;
	}




	public MemberService getMemberService() {
		return memberService;
	}
	@Resource
	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}




	public String getUrl() {
		return url;
	}




	public void setUrl(String url) {
		this.url = url;
	}
	

}
